"""
   author: 陈亚敏
   data: 2021/12/10  16:21
   project: 1
"""
# 1.迭代器
# class Itera():
#     def __init__(self):
#         #存放传进来的可迭代对象
#         self.a=0
#         self.b=1
#     def __next__(self,n):
#         self.a,self.b=self.b,self.a+self.b
#         return self.a
#     def __iter__(self):
#         return self
#
# a=Itera()
# for i in range(9):
#     print(a.__next__(100))

# 2.ATM
import time


class ATM():
    money = 50000
    area = 'changsha'
    now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())

    def draw_money(self, getmoney, user, username):
        if getmoney <= self.money and getmoney <= user.user[username]['money']:
            self.money -= getmoney
            user.user[username]['money'] -= getmoney
            print(f"{username},您好，您于{self.now_time}在{self.area}取了{getmoney}元\n账户目前剩余{user.user[username]['money']}元")
        elif getmoney > user.user[username]['money']:
            print('您的账户余额不足！')
        else:
            print('对不起,ATM余额不足!')

    def save_money(self, savemoney, user, username):
        self.money += savemoney
        user.user[username]['money'] += savemoney
        print(f"{username},您好，您于{self.now_time}在{self.area}存了{savemoney}元\n账户目前剩余{user.user[username]['money']}元")


class User():
    user = {'cym': {'passwd': '11223', 'money': 10000},  # 用户表
            'hj': {'passwd': '3333', 'money': 2000}}

    def __init__(self, username):
        self.username = username

    def login(self):
        passwd = input(f'{self.username},你好！请输入你的密码：')
        if self.username in self.user and passwd == self.user[self.username]['passwd']:
            return 1
        else:
            print("用户名密码有误")


cym = User(username='cym')
atm1 = ATM()

if cym.login():
    while 1:
        chose = input('取钱1，存钱2,按q退出！：')
        if chose == '1':
            draw = int(input("你要取多少钱？请输入金额："))
            atm1.draw_money(draw, cym, 'cym')

        if chose == '2':
            save = int(input("你要存多少钱？请输入金额："))
            atm1.save_money(save, cym, 'cym')

        if chose == 'q':
            break
        else:
            continue
    print('886')
